import { HttpDelTemplate, HttpSetActiveTemplate, HttpTemplateList } from '../../../service/notice'
import TableList from '../../../components/templates/tablelist'
import mixin from '../mixin'

export default {
    mixins: [TableList, mixin],
    data () {
        return {
            isMixin: true,
            Tools: { show: true },
            formData: {
                search: {
                    EQ_status: null
                }
            },
            Searchs: {
                show: true,
                labelWidth: 90,
            },
            Plugins: { show: true },
        }
    },
    methods: {
        ajaxRequest: HttpTemplateList,
        handleOperates (params, type, batch) {
            if (batch === true) {
                params = (params || this.checkedData.join(',')) + ''
                if (!params.length) return this.$Message.warning('请选择至少一条数据')
            }
            switch (type) {
                case 'del':
                    this.operate = {
                        show: false,
                        alert: 'error',
                        params: { id: params },
                        title: '删除通知模板',
                        ajaxRequest: HttpDelTemplate,
                    }
                    break
                case 'setActive':
                    this.operate = {
                        show: true,
                        alert: (params.active == 1) ? 'success' : 'error',
                        params,
                        title: (params.active == 1 ? '启用' : '禁用') + '该条目',
                        ajaxRequest: HttpSetActiveTemplate
                    }
                    break
            }
        },
        // 操作下的列表展示内容
        getOperateNodeMap (row) {
            const { id, active } = row
            return [
                //     {
                //     label: '查看',
                //     show: true,
                //     to: {
                //         name: 'noticeTemplateUpdate',
                //         params: { type: "query" },
                //         query: { id },
                //         target: "_blank"
                //     }
                // },
                {
                    label: '编辑',
                    show: true,
                    to: {
                        name: 'noticeTemplateUpdate',
                        params: { type: 'edit' },
                        query: { id }
                    }
                }, {
                    label: '失效',
                    show: false,
                    params: id,
                    operate: 'invalid'
                }, {
                    label: '删除',
                    show: false,
                    params: id,
                    operate: 'del'
                }, {
                    label: active == 1 ? '禁用' : '启用',
                    show: true,
                    params: { id, active: active == 1 ? 2 : 1 },
                    operate: 'setActive'
                }
            ]
        },
    },
    computed: {
        ToolsData () {
            return [
                {
                    label: '添加',
                    theme: 'primary',
                    to: {
                        name: 'noticeTemplateUpdate',
                        params: { type: 'add' },
                    }
                }
            ]
        },
        SearchsData () {
            return [
                {
                    label: '模板名称',
                    key: 'CN_title',
                    tag: 'Input',
                    show: true,
                },
                {
                    label: '类型',
                    tag: 'Select',
                    key: 'EQ_bizeventTypeId',
                    show: true,
                    options: this.getNoticeEevntTypes,
                },
                {
                    label: '模板描述',
                    key: 'EQ_brief',
                    tag: 'Input',
                    show: true,
                },
                {
                    label: '状态',
                    tag: 'Select',
                    key: 'EQ_active',
                    options: this.getTemplateStatus,
                },
                {
                    label: '创建人',
                    key: 'EQ_createdName',
                    tag: 'Input',
                },
            ]
        },
        columns () {
            return [
                {
                    type: 'selection',
                    width: 40,
                    align: 'center',
                    formName: 'id'
                },
                {
                    title: '操作',
                    width: 110,
                    render: this.getOperateNodes
                },
                {
                    title: '模板ID',
                    key: 'id',
                    width: 70,
                },
                {
                    title: '模板名称',
                    key: 'title',
                }, {
                    title: '模板描述',
                    key: 'brief',
                }, {
                    title: '类型',
                    key: 'bizeventTypeId',
                    render: (h, { row }) => this.findRenderLabel(this.getNoticeEevntTypes, row.bizeventTypeId),
                },
                {
                    title: '状态',
                    key: 'active',
                    render: (h, { row }) => this.findRenderLabel(this.getTemplateStatus, row.active),
                },
                {
                    title: '创建时间',
                    key: 'createdAt',
                }, {
                    title: '更新时间',
                    key: 'updatedAt',
                }]
        },
    },
}




